package com.chutoutian.controller;

import com.chutoutian.common.Code;
import com.chutoutian.po.Address;
import com.chutoutian.service.AddressService;
import com.chutoutian.vo.ResponseMessage;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/v1")
public class AddressController {

    @Resource
    private AddressService addressService;

    @GetMapping("/address")
    public Object find(Address address) {
        return addressService.find(address);
    }

    @GetMapping("/address/{id}")
    public Object get(@PathVariable("id") String id) {
        return addressService.get(id);
    }

    @PostMapping("/address")
    public Object add(@RequestBody Address address) {
        addressService.add(address);
        return new ResponseMessage.Builder().code(Code.CODE_200).bulid();
    }

    @PutMapping("/address")
    public Object update(@RequestBody Address address) {
        addressService.update(address);
        return new ResponseMessage.Builder().code(Code.CODE_200).bulid();
    }

    @DeleteMapping("/address/{id}")
    public Object delete(@PathVariable("id") String id) {
        addressService.delete(id);
        return new ResponseMessage.Builder().code(Code.CODE_200).bulid();
    }

}
